package com.lide.rtmpplayer;
import android.app.Activity;  
import android.app.AlertDialog;  
import android.os.Bundle;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.widget.Button;  
import android.widget.EditText;  
import android.support.v7.app.ActionBarActivity;


public class LIDE extends ActionBarActivity {


	 /** Called when the activity is first created. */  
    Button btnShow;  
    Button btnPlay; 
    Button btnPause;
    Button btnReplay;
    Button btnStop;
    EditText edtInput;
    Player player;
    boolean isplaying;
   
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
          
        btnShow=(Button)findViewById(R.id.btnShow);//控件与代码绑定  
        btnPlay=(Button)findViewById(R.id.btnPlay);//控件与代码绑定
        btnPause=(Button)findViewById(R.id.btnPause);//控件与代码绑定
        btnReplay=(Button)findViewById(R.id.btnReplay);//控件与代码绑定 
        btnStop=(Button)findViewById(R.id.btnStop);//控件与代码绑定 
        edtInput=(EditText)findViewById(R.id.edtInput);//控件与代码绑定  
        btnShow.setOnClickListener(new ClickListener());//使用点击事件  
        btnPlay.setOnClickListener(new ClickListener());//使用点击事件  
        btnPause.setOnClickListener(new ClickListener());
        btnReplay.setOnClickListener(new ClickListener());
        btnStop.setOnClickListener(new ClickListener());
        
        player = new Player();
        player.Init();
        isplaying = false;
        
    }  
      
    class  ClickListener implements OnClickListener  
    {  
        public void onClick(View v)  
        {  
        	
            if(v==btnShow)  
            {  
            	
                new AlertDialog.Builder(LIDE.this)  
                .setIcon(android.R.drawable.ic_dialog_alert)  
                .setTitle("信息")  
                .setMessage(edtInput.getText())  
                .show();          
            }  
            else if(v==btnPlay)  
            {  
                //edtInput.setText(reply);
            	if(!isplaying){
            		player.Open(edtInput.getText().toString());
            		isplaying = true;
            	}
            	player.Play();
            }  
            else if(v==btnPause)
            {
            	if(isplaying){
            		player.Pause();
            	}
            }
            else if(v==btnReplay)
            {
            	if(isplaying){
            		player.Close();
            		isplaying = false;
            	}
            	player.Open(edtInput.getText().toString());
            	isplaying = true;
            	player.Play();
            }
            else if(v==btnStop)
            {
            	if(isplaying){
            		player.Close();
            		isplaying = false;
            	}
            }
        }  
    }  
    @Override
    protected void onDestroy() {
    	player.Deinit();
    }  
}
